const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const { connectDB } = require('./config/database');
const { connectRedis } = require('./config/redis');
const errorHandler = require('./middleware/errorHandler');
const router = require('./routes');

const app = new Koa();
const PORT = process.env.PORT || 3000;

// Connect to MongoDB
connectDB();

// Connect to Redis
connectRedis();

// Middleware
app.use(errorHandler);
app.use(bodyParser());

// Routes
app.use(router.routes());
app.use(router.allowedMethods());

app.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});